/*
 * Copyright (c) 2010, University of Innsbruck, Austria.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * You should have received a copy of the GNU Lesser General Public License along
 * with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package at.sti2.sepn.agent.component;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import at.sti2.sepn.agent.exception.AgentComponentException;
import at.sti2.sepn.core.buffer.EventBuffer;

public abstract class AbstractAgentComponent {

	private Map <String, EventBuffer> inputs = null;
	private Map <String, EventBuffer> outputs = null;
	
	public AbstractAgentComponent(){
		inputs = new HashMap <String, EventBuffer>();
		outputs = new HashMap <String, EventBuffer> ();
	}
	
	/**
	 * Getters and setters
	 */
	public void addInput(String inputId, EventBuffer input) throws AgentComponentException{
		
		if (inputs.containsKey(inputId))
			throw new AgentComponentException("Input with the identifier " + inputId + " already exists.");
		
		inputs.put(inputId, input);
	}
	
	public void addOutput(String outputId, EventBuffer output) throws AgentComponentException{
		
		if (outputs.containsKey(outputId))
			throw new AgentComponentException("Output with the identifier " + outputId + " already exists.");
		
		outputs.put(outputId, output);
	}
	
	public Set<String> getInputIds(){
		return inputs.keySet();
	}
	
	public Set<String> getOutputIds(){
		return outputs.keySet();
	}
	
	public EventBuffer getInputById(String inputId){
		EventBuffer input = null;
		
		if ((inputId!=null)&&(!inputId.equals("")))
			if (inputs.containsKey(inputId))
				input = inputs.get(inputId);
		
		return input;
	}
	
	public EventBuffer getOutputById(String outputId){
		EventBuffer output = null;
		
		if ((outputId!=null)&&(!outputId.equals("")))
			if (outputs.containsKey(outputId))
				output = inputs.get(outputId);
		
		return output;
	}
}
